/**
  * 系统管理--用户管理的单例对象
 */
var QuestClass = {
    id: "QuestClassTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    deptid:0
};

/**
 * 初始化表格的列
 */
QuestClass.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '类别名称', field: 'className', visible: true, align: 'center', valign: 'middle'},
            //{title: '课程名称', field: 'courseId', visible: true, align: 'center', valign: 'middle'},
            {title: '对象', field: 'target', visible: true, align: 'center', valign: 'middle'},
            {title: '发布单位', field: 'publishFrom', visible: true, align: 'center', valign: 'middle'},
            {title: '发布单位', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
        ];
    return columns;
};

/**
 * 检查是否选中
 */
QuestClass.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    alert(selected.id);
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        QuestClass.seItem = selected;
        return true;
    }
};

QuestClass.singleCheck = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
    	if (selected.length >1) {
            Feng.info("请先选中表格中的某一记录！");
            return false;
        }else{
        	 QuestClass.seItem = selected[0];
             return true;
        } 
    }
};

/**
 * 点击添加
 */
QuestClass.openAddQuestClass = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['50%', '50%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/questClass/toAdd'
    });
    this.layerIndex = index;
};


/**
 * 提交修改
 */
QuestClass.publish = function() {

	if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '编辑',
            area: ['90%', '90%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/questClass/publishById/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};


/**
 * 点击修改按钮时
 * @param userId 
 */
QuestClass.openChange = function () {
    if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '编辑',
            area: ['90%', '90%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/questClass/toUpdate/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};
QuestClass.openView = function(){
	if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/questClass/view/' + this.seItem.id
        });
        this.layerIndex = index;
    }
}

QuestClass.openDel = function () {
    if (this.singleCheck()) {
    	
    	var id=this.seItem.id;
        var operation = function(){
            var userId = QuestClass.seItem.id;
            var ajax = new $ax(Feng.ctxPath + "/questClass/delete", function (data) {
            	if(data.resultCode==0){
            		Feng.success("删除成功!");
            		QuestClass.table.refresh();
            	}else{
            		Feng.error(data.msg + "!");
            	}              
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", id);
            ajax.start();
        };

        Feng.confirm("是否删除选中的类型?",operation);
    }
};




QuestClass.resetSearch = function () {
    $("#courseName").val("");
    $("#className").val("");
    QuestClass.table.refreshOptions({pageNumber:1});
    QuestClass.search();
}

QuestClass.search = function () {
    var queryData = {};
    queryData['courseName'] = $("#courseName").val();
    queryData['className'] = $("#className").val()
    QuestClass.table.refreshOptions({pageNumber:1});
    QuestClass.table.refresh({query: queryData});
}

QuestClass.openQuestClassOption = function () {
	
    if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '题目答案选项',
            area: ['800px', '520px'], // 宽高
            fix: false, // 不固定
            maxmin: true,
            content: Feng.ctxPath + '/questClass/QuestClass_option/' + QuestClass.seItem.id
        });
        this.layerIndex = index;
    }
};


$(function () {
	var paramsId =[
	      {
	    	  "key":"courseName",
	    	  "type":"input",
	    	  "id":"courseName"
	       },
	       {
		    	  "key":"className",
		    	  "type":"input",
		    	  "id":"className"
		       }
	   /*{
	       "key":"courseName",
	       "type":"input",
	       "id":"courseName"
	   },
	   {
		   "key":"termName",
		   "type":"select",
		   "id":"termName"
	   },
	   {
		   "key":"catagoryId",
		   "type":"select",
		   "id":"catagoryId"
	   }*/
	];
    var defaultColunms = QuestClass.initColumn();
    var table = new BSTable("QuestClassTable", "/questClass/list", defaultColunms,paramsId);
    table.setPaginationType("server");
    QuestClass.table = table.init();
});






